Skip to content

audio: mux: Fix use of incorrect macro#10838

Open
tmleman wants to merge 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/audio/mux/fix_overrun
Open

audio: mux: Fix use of incorrect macro#10838
tmleman wants to merge 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/audio/mux/fix_overrun

Conversation

@tmleman

@tmleman tmleman commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

comp_buffer_get_sink_component(b) inside a for_each_producer loop returns mux itself, making the pipeline comparison always false and audio_stream_set_overrun() unreachable.

Issue found using semgrep with custom rules.

@tmleman tmleman requested a review from fkwasowi as a code owner June 3, 2026 15:20
Copilot AI review requested due to automatic review settings June 3, 2026 15:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a logic error in the DEMUX pre-start trigger path where the wrong buffer-component accessor prevented the cross-pipeline comparison from ever succeeding, making audio_stream_set_overrun() unreachable.

Changes:

  • Replace comp_buffer_get_sink_component() with comp_buffer_get_source_component() when checking pipeline ownership for producer buffers in demux_trigger().

Comment thread src/audio/mux/mux.c Outdated
@tmleman

tmleman commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

I'm developing (with the help of AI) custom semgrep rules that will detect incorrect use of macros (mostly related to sink/source api). This PR is fixing one (and only) finding in current code. Here is scan result:

┌────────────────┐
│ 1 Code Finding │
└────────────────┘

    src/audio/mux/mux.c
   ❯❯❱ scripts.scan.semgrep.sof-producer-loop-wrong-component-getter
          ❰❰ Blocking ❱❱
          comp_buffer_get_sink_component() called on producer buffer 'b' inside a comp_dev_for_each_producer
          loop. In this loop, dev is buf->source, so get_sink_component(b) returns dev itself — not the
          upstream neighbour. Use comp_buffer_get_source_component(b) instead.

          295┆ if (comp_buffer_get_sink_component(b)->pipeline != mod->dev->pipeline)

@lyakh @softwarecki can you help review and verify that scan is working correctly.

Comment thread src/audio/mux/mux.c Outdated
Comment thread src/audio/mux/mux.c Outdated
@tmleman tmleman force-pushed the topic/upstream/pr/audio/mux/fix_overrun branch from d413771 to f367528 Compare June 10, 2026 13:03
@tmleman tmleman requested review from abonislawski and lyakh June 10, 2026 13:03
demux_trigger() checks for cross-pipeline sinks to set the overrun_permitted
flag. Commit 96b4fdb ("buf: use API for iteration bsource_list in
components") incorrectly converted the bsink_list iteration to
comp_dev_for_each_producer instead of comp_dev_for_each_consumer.

Since demux has 1 input and multiple outputs, the loop must iterate over
consumers (sinks), not producers (sources). The incorrect iterator caused
the pipeline comparison to never match, making audio_stream_set_overrun()
unreachable.

Fix by using comp_dev_for_each_consumer with comp_buffer_get_sink_component
and add a defensive NULL check on the returned component pointer.

Issue found using semgrep with custom rules.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants